<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>订单详情 - 后台</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; background-color: #f4f4f4; }
        .container { max-width: 960px; margin: 20px auto; padding: 30px; border: 1px solid #ddd; border-radius: 8px; background-color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
        h1 { color: #333; text-align: center; margin-bottom: 20px; }
        .order-info, .order-items { margin-bottom: 30px; padding: 20px; border: 1px solid #eee; border-radius: 5px; background-color: #fdfdfd; }
        .order-info h2, .order-items h2 { color: #007bff; margin-top: 0; margin-bottom: 15px; }
        .order-info p { margin-bottom: 8px; line-height: 1.6; }
        table { width: 100%; border-collapse: collapse; margin-top: 15px; }
        th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
        th { background-color: #f2f2f2; }
        tfoot th { text-align: right; }
        .back-link { display: block; margin-top: 20px; text-align: center; }
        .back-link a { color: #007bff; text-decoration: none; }
        .back-link a:hover { text-decoration: underline; }
    </style>
</head>
<body>
    <div class="container">
        <h1>订单详情</h1>

        <?php if (!empty($order)): ?>
            <div class="order-info">
                <h2>订单信息</h2>
                <p><strong>订单号:</strong> <?= $order->order_sn ?></p>
                <p><strong>用户:</strong> <?= $order->user->username ?? '未知用户' ?></p>
                <p><strong>总金额:</strong> ¥<?= number_format($order->total_price, 2) ?></p>
                <p><strong>订单状态:</strong> <?= $order->status == 'pending' ? '待支付' : '已完成' ?></p>
                <p><strong>创建时间:</strong> <?= $order->create_time ?></p>
            </div>

            <div class="order-items">
                <h2>商品列表</h2>
                <?php if (!empty($order->orderItems)): ?>
                    <table>
                        <thead>
                            <tr>
                                <th>商品名称</th>
                                <th>单价</th>
                                <th>数量</th>
                                <th>小计</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($order->orderItems as $item): ?>
                                <tr>
                                    <td><?= $item->product_name ?></td>
                                    <td>¥<?= number_format($item->product_price, 2) ?></td>
                                    <td><?= $item->quantity ?></td>
                                    <td>¥<?= number_format($item->product_price * $item->quantity, 2) ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="3">总计</th>
                                <th>¥<?= number_format($order->total_price, 2) ?></th>
                            </tr>
                        </tfoot>
                    </table>
                <?php else: ?>
                    <p>该订单没有商品项。</p>
                <?php endif; ?>
            </div>
        <?php else: ?>
            <p>订单不存在或无法查看。</p>
        <?php endif; ?>
        
        <p class="back-link"><a href="{:Url('admin/index/orderList')}">返回订单列表</a></p>
    </div>
</body>
</html>